/* Though originally coded by Eli Gottlieb in the year 2006, this code rests in the public domain.
 * The point of a separate file full of helper routines is that these exist and work independently of any driver,
 * but at the same time are not primitives of the EDI runtime.
 * You could build these into an EDI helper library, but don't have to. */
/* Modified by thePowersGang (John Hodge)
 */

#include <edi.h>

/**
 * \fn bool edi_string_equal(edi_string_t x, edi_string_t y)
 * \brief Compare two EDI strings
 */
bool edi_string_equal(edi_string_t x, edi_string_t y)
{
	int i;
	for( i = 0; i < EDI_STRING_LENGTH; i++)
		if(x[i] != y[i])
			return false;
	return true;
}

/**
 * \fn bool descends_from(data_pointer object_class, edi_string_t desired_class)
 * \brief Checks if #current_class is a decendant of #desired_class
 */
bool descends_from(data_pointer object_class, edi_string_t desired_class)
{
	edi_string_ptr_t current_class;
	current_class = get_object_class(object_class);
	while(!edi_string_equal(current_class, desired_class))
	{
		current_class = get_class_parent(current_class);
		if(edi_string_equal(current_class,""))
			return false;
	};
	return true;
}

/**
 * \fn data_pointer get_actual_class(edi_string_t ancestor, int32_t num_objects, edi_object_metadata_t *objects)
 * \brief Finds an instance of #ancestor in #objects
 */
data_pointer get_actual_class(edi_string_t ancestor, int32_t num_objects, edi_object_metadata_t *objects)
{
	 int	i;
	edi_string_ptr_t	tmpStr;
	for( i = 0; i < num_objects; i++ )
	{
		tmpStr = get_object_class( &objects[i] );
		if(edi_string_equal(tmpStr, ancestor))
			return objects[i].object_class;
	}
	return NULL;
}
